/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import Funcoes.Funcao;
import classes.Cliente;
import classes.Equipamento;
import classes.Venda;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.swing.JOptionPane;

/**
 *
 * @author sabrina
 */
public class vendaEquipamento extends javax.swing.JInternalFrame {

    EntityManager gerenciador;
    Query consulta;
    Cliente cliente = new Cliente();
    Equipamento equipamento = new Equipamento();
    Venda venda = new Venda();

    /**
     * Creates new form vendaEquipamento
     */
    public vendaEquipamento() {

        initComponents();

        txt_nome_cliVenda.setEnabled(false);
        txt_id_cliVenda.setEnabled(false);
        txt_pedido.setEnabled(false);
        txt_valor.setEnabled(false);

        txt_equipInfo.setEnabled(false);
        jrb_cartao_credito.setEnabled(false);
        jrb_cartao_debito.setEnabled(false);
        jrb_avista.setEnabled(false);
        venda_salvar.setEnabled(false);
        venda_cancelar.setEnabled(false);

// programa começa  com todos botoes desativados 
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painel_venda1 = new javax.swing.JPanel();
        venda_lbl1 = new javax.swing.JLabel();
        venda_lbl2 = new javax.swing.JLabel();
        venda_lbl3 = new javax.swing.JLabel();
        txt_busca = new javax.swing.JFormattedTextField();
        txt_nome_cliVenda = new javax.swing.JTextField();
        txt_id_cliVenda = new javax.swing.JTextField();
        btn_buscaCli = new javax.swing.JButton();
        painel_venda2 = new javax.swing.JPanel();
        venda_lbl14 = new javax.swing.JLabel();
        txt_codEquip = new javax.swing.JTextField();
        btn_buscaEquip = new javax.swing.JButton();
        venda_lbl6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txt_equipInfo = new javax.swing.JTextArea();
        lbl_equipamento = new javax.swing.JLabel();
        venda_lbl15 = new javax.swing.JLabel();
        venda_cancelar = new javax.swing.JButton();
        venda_salvar = new javax.swing.JButton();
        painel_venda3 = new javax.swing.JPanel();
        jrb_avista = new javax.swing.JRadioButton();
        jrb_cartao_debito = new javax.swing.JRadioButton();
        jrb_cartao_credito = new javax.swing.JRadioButton();
        venda_lbl10 = new javax.swing.JLabel();
        txt_valor = new javax.swing.JFormattedTextField();
        venda_lbl4 = new javax.swing.JLabel();
        txt_pedido = new javax.swing.JTextField();
        lbl_data = new javax.swing.JLabel();
        txt_data = new javax.swing.JFormattedTextField();
        venda_lbl7 = new javax.swing.JLabel();

        setClosable(true);
        setTitle("Venda De Equipamentos");
        setInheritsPopupMenu(true);
        setMinimumSize(new java.awt.Dimension(62, 33));
        setNormalBounds(new java.awt.Rectangle(0, 0, 62, 0));
        setPreferredSize(new java.awt.Dimension(700, 610));

        painel_venda1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        venda_lbl1.setText("CPF");

        venda_lbl2.setText("Nome");

        venda_lbl3.setText("ID Cliente");

        try {
            txt_busca.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txt_busca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_buscaActionPerformed(evt);
            }
        });

        txt_nome_cliVenda.setEditable(false);
        txt_nome_cliVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_nome_cliVendaActionPerformed(evt);
            }
        });

        txt_id_cliVenda.setEditable(false);
        txt_id_cliVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_id_cliVendaActionPerformed(evt);
            }
        });

        btn_buscaCli.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botao_procurar.png"))); // NOI18N
        btn_buscaCli.setText("Pesquisar");
        btn_buscaCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_buscaCliActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painel_venda1Layout = new javax.swing.GroupLayout(painel_venda1);
        painel_venda1.setLayout(painel_venda1Layout);
        painel_venda1Layout.setHorizontalGroup(
            painel_venda1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_venda1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(painel_venda1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(venda_lbl1)
                    .addComponent(venda_lbl2))
                .addGap(30, 30, 30)
                .addGroup(painel_venda1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txt_nome_cliVenda)
                    .addComponent(txt_busca, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btn_buscaCli)
                .addGap(46, 46, 46)
                .addComponent(venda_lbl3)
                .addGap(42, 42, 42)
                .addComponent(txt_id_cliVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        painel_venda1Layout.setVerticalGroup(
            painel_venda1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_venda1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painel_venda1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painel_venda1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(venda_lbl1)
                        .addComponent(txt_busca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btn_buscaCli))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painel_venda1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(venda_lbl3)
                        .addComponent(txt_id_cliVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painel_venda1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(venda_lbl2)
                    .addComponent(txt_nome_cliVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        painel_venda2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        venda_lbl14.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        venda_lbl14.setText("Código do equipamento: ");

        txt_codEquip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_codEquipActionPerformed(evt);
            }
        });

        btn_buscaEquip.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botao_procurar.png"))); // NOI18N
        btn_buscaEquip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_buscaEquipActionPerformed(evt);
            }
        });

        venda_lbl6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        venda_lbl6.setText("Informação sobre o equipamento ");

        txt_equipInfo.setEditable(false);
        txt_equipInfo.setColumns(20);
        txt_equipInfo.setRows(5);
        txt_equipInfo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jScrollPane2.setViewportView(txt_equipInfo);

        lbl_equipamento.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        venda_lbl15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        venda_lbl15.setText("Equipamento");

        javax.swing.GroupLayout painel_venda2Layout = new javax.swing.GroupLayout(painel_venda2);
        painel_venda2.setLayout(painel_venda2Layout);
        painel_venda2Layout.setHorizontalGroup(
            painel_venda2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_venda2Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(venda_lbl14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txt_codEquip, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(btn_buscaEquip, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                .addComponent(venda_lbl15)
                .addGap(29, 29, 29)
                .addComponent(lbl_equipamento, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34))
            .addGroup(painel_venda2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painel_venda2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(venda_lbl6)
                .addGap(197, 197, 197))
        );
        painel_venda2Layout.setVerticalGroup(
            painel_venda2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painel_venda2Layout.createSequentialGroup()
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(painel_venda2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painel_venda2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(painel_venda2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_codEquip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(venda_lbl14))
                        .addComponent(btn_buscaEquip))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painel_venda2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(venda_lbl15)
                        .addComponent(lbl_equipamento, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(venda_lbl6)
                .addGap(8, 8, 8)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(92, 92, 92))
        );

        venda_cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/remove.png"))); // NOI18N
        venda_cancelar.setText("Cancelar ");
        venda_cancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                venda_cancelarMouseClicked(evt);
            }
        });
        venda_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                venda_cancelarActionPerformed(evt);
            }
        });

        venda_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/accept.png"))); // NOI18N
        venda_salvar.setText("Salvar");
        venda_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                venda_salvarActionPerformed(evt);
            }
        });

        painel_venda3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jrb_avista.setText("À vista");
        jrb_avista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb_avistaActionPerformed(evt);
            }
        });

        jrb_cartao_debito.setText("Carrtão de débito");
        jrb_cartao_debito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb_cartao_debitoActionPerformed(evt);
            }
        });

        jrb_cartao_credito.setText("Cartão de crédito");
        jrb_cartao_credito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb_cartao_creditoActionPerformed(evt);
            }
        });

        venda_lbl10.setText("Valor:");

        txt_valor.setEditable(false);
        txt_valor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getCurrencyInstance())));

        venda_lbl4.setText("Numero do Pedido ");

        txt_pedido.setEditable(false);
        txt_pedido.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        txt_pedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_pedidoActionPerformed(evt);
            }
        });

        lbl_data.setText("Data:");

        try {
            txt_data.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txt_data.setToolTipText("dia / mes / ano ");

        javax.swing.GroupLayout painel_venda3Layout = new javax.swing.GroupLayout(painel_venda3);
        painel_venda3.setLayout(painel_venda3Layout);
        painel_venda3Layout.setHorizontalGroup(
            painel_venda3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_venda3Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(painel_venda3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(painel_venda3Layout.createSequentialGroup()
                        .addComponent(venda_lbl10)
                        .addGap(18, 18, 18)
                        .addComponent(txt_valor, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(55, 55, 55)
                        .addComponent(lbl_data)
                        .addGap(28, 28, 28)
                        .addComponent(txt_data, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(painel_venda3Layout.createSequentialGroup()
                        .addComponent(jrb_cartao_credito)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jrb_cartao_debito)))
                .addGroup(painel_venda3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painel_venda3Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(venda_lbl4)
                        .addGap(18, 18, 18)
                        .addComponent(txt_pedido, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painel_venda3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jrb_avista)
                        .addGap(80, 80, 80))))
        );
        painel_venda3Layout.setVerticalGroup(
            painel_venda3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painel_venda3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painel_venda3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrb_cartao_debito)
                    .addComponent(jrb_avista)
                    .addComponent(jrb_cartao_credito))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                .addGroup(painel_venda3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(painel_venda3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(venda_lbl4)
                        .addComponent(txt_pedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txt_data)
                        .addComponent(lbl_data))
                    .addGroup(painel_venda3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(venda_lbl10)
                        .addComponent(txt_valor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        venda_lbl7.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        venda_lbl7.setText("Forma de Pagamento");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(149, 149, 149)
                .addComponent(venda_salvar, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(venda_cancelar)
                .addGap(136, 136, 136))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(painel_venda3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(painel_venda1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(painel_venda2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(32, 32, 32))
            .addGroup(layout.createSequentialGroup()
                .addGap(280, 280, 280)
                .addComponent(venda_lbl7)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(painel_venda1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(painel_venda2, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(venda_lbl7)
                .addGap(18, 18, 18)
                .addComponent(painel_venda3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(venda_salvar)
                    .addComponent(venda_cancelar))
                .addContainerGap(76, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txt_buscaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_buscaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_buscaActionPerformed

    private void txt_nome_cliVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_nome_cliVendaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_nome_cliVendaActionPerformed

    private void txt_id_cliVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_id_cliVendaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_id_cliVendaActionPerformed

    private void btn_buscaCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_buscaCliActionPerformed
        gerenciador = Funcao.conectar(); // abre a conexão com o banco 

        consulta = gerenciador.createQuery("select c from Cliente c where c.cliCpf = :cliCpf"); //HQl
        consulta.setParameter("cliCpf", txt_busca.getText());

        cliente = (Cliente) consulta.getSingleResult();

//        this.txt_pedido.setText("" + cliente.getId());
        this.txt_nome_cliVenda.setText(cliente.getCliNome());
        this.txt_id_cliVenda.setText("" + cliente.getId());

        Funcao.fechar(gerenciador); // fecha conexão com o banco 

        this.txt_nome_cliVenda.setEnabled(true);
        this.txt_id_cliVenda.setEnabled(true);
        this.txt_pedido.setEnabled(true);
        this.btn_buscaEquip.setEnabled(true);
        this.txt_codEquip.setEnabled(true);

// ativa todos os botoes e campos ao  clicar 
    }//GEN-LAST:event_btn_buscaCliActionPerformed

    private void venda_cancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_venda_cancelarMouseClicked
        System.exit(0);        // fecha a tela ao clicar
    }//GEN-LAST:event_venda_cancelarMouseClicked

    private void venda_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_venda_cancelarActionPerformed
        int resposta = JOptionPane.showConfirmDialog(null, "Você realmente deseja cancelar esta venda ? ", "Finalizando venda ", JOptionPane.YES_NO_OPTION);
        if (resposta == 0) {
            this.reiniciaFormulario();
        }

    }//GEN-LAST:event_venda_cancelarActionPerformed

    private void venda_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_venda_salvarActionPerformed
        
        gerenciador = Funcoes.Funcao.conectar();
        
        venda.setCliente(cliente);
        equipamento.setEqui_quant(equipamento.getEqui_quant()-1);
        
        venda.setEquipamento(equipamento);
        venda.setData(this.txt_data.getText());
        
        if (jrb_cartao_credito.isSelected()) {
            venda.setTipoCartaoCredito(this.jrb_cartao_credito.isSelected());
        }

        if (jrb_cartao_debito.isSelected()) {
            venda.setTipoCartaoDebito(this.jrb_cartao_debito.isSelected());
        }

        if (jrb_avista.isSelected()) {
            venda.setTipoAVista(this.jrb_avista.isSelected());
        }

        Funcoes.Funcao.persistir(gerenciador, venda);

        Funcoes.Funcao.fechar(gerenciador);//fecha conexão 

        this.reiniciaFormulario();

        JOptionPane.showMessageDialog(null, "Venda efetuada com sucesso!"); // se salvou retorna ok
        JOptionPane.showMessageDialog(null, "Numero do pedido : " + venda.getIdvenda());
    }//GEN-LAST:event_venda_salvarActionPerformed

    private void txt_pedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_pedidoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_pedidoActionPerformed

    private void jrb_cartao_debitoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb_cartao_debitoActionPerformed

        jrb_cartao_credito.setEnabled(false);        // desativa todos e ativa c. debito
        jrb_cartao_debito.setEnabled(true);
        jrb_avista.setEnabled(false);
//comandos para ativar segmento da venda
        txt_valor.setEnabled(true);
    }//GEN-LAST:event_jrb_cartao_debitoActionPerformed

    private void jrb_cartao_creditoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb_cartao_creditoActionPerformed

        jrb_cartao_credito.setEnabled(true); // desativa todos e ativa c. credito
        jrb_cartao_debito.setEnabled(false);
        jrb_avista.setEnabled(false);
        //comandos para ativar segmento da venda

        txt_valor.setEnabled(true);


    }//GEN-LAST:event_jrb_cartao_creditoActionPerformed

    private void jrb_avistaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb_avistaActionPerformed

        jrb_cartao_credito.setEnabled(false);
        jrb_cartao_debito.setEnabled(false);
        jrb_avista.setEnabled(true);        //desativa todos e ativa c. credito.
        //comandos para ativar segmento da venda
        txt_valor.setEnabled(true);
    }//GEN-LAST:event_jrb_avistaActionPerformed

    private void btn_buscaEquipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_buscaEquipActionPerformed
 
        gerenciador = Funcao.conectar();

        consulta = gerenciador.createQuery("select c from Equipamento c where c.equi_cod = :equi_cod"); //HQl
        consulta.setParameter("equi_cod", txt_codEquip.getText());

        equipamento = (Equipamento) consulta.getSingleResult();
equipamento.setEqui_quant(equipamento.getEqui_quant()-1);
        //this.lbl_codigo_equip.setText("" + equipamento.getIdEquip());
        this.lbl_equipamento.setText(equipamento.getEqui_nome());
        this.txt_valor.setText(equipamento.getEqui_preco());
        this.txt_equipInfo.setText(equipamento.getEqui_inf());

        Funcao.fechar(gerenciador);
//******************************************

        this.venda_lbl10.setEnabled(true);
        this.txt_valor.setEnabled(true);
        this.jrb_cartao_credito.setEnabled(true);
        this.jrb_cartao_debito.setEnabled(true);
        this.jrb_avista.setEnabled(true);
        this.txt_equipInfo.setEnabled(true);
        jrb_cartao_credito.setEnabled(true);
        jrb_cartao_debito.setEnabled(true);
        jrb_avista.setEnabled(true);
        venda_salvar.setEnabled(true);
        venda_cancelar.setEnabled(true);
//******************************************
        this.txt_busca.setEnabled(false);
        this.txt_nome_cliVenda.setEnabled(false);
        this.txt_id_cliVenda.setEnabled(false);
        this.btn_buscaCli.setEnabled(false);
        this.txt_pedido.setEnabled(false);// desativa os botoes para buscar cliente. 


    }//GEN-LAST:event_btn_buscaEquipActionPerformed

    private void txt_codEquipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_codEquipActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txt_codEquipActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_buscaCli;
    private javax.swing.JButton btn_buscaEquip;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JRadioButton jrb_avista;
    private javax.swing.JRadioButton jrb_cartao_credito;
    private javax.swing.JRadioButton jrb_cartao_debito;
    private javax.swing.JLabel lbl_data;
    private javax.swing.JLabel lbl_equipamento;
    private javax.swing.JPanel painel_venda1;
    private javax.swing.JPanel painel_venda2;
    private javax.swing.JPanel painel_venda3;
    private javax.swing.JFormattedTextField txt_busca;
    private javax.swing.JTextField txt_codEquip;
    private javax.swing.JFormattedTextField txt_data;
    private javax.swing.JTextArea txt_equipInfo;
    private javax.swing.JTextField txt_id_cliVenda;
    private javax.swing.JTextField txt_nome_cliVenda;
    private javax.swing.JTextField txt_pedido;
    private javax.swing.JFormattedTextField txt_valor;
    private javax.swing.JButton venda_cancelar;
    private javax.swing.JLabel venda_lbl1;
    private javax.swing.JLabel venda_lbl10;
    private javax.swing.JLabel venda_lbl14;
    private javax.swing.JLabel venda_lbl15;
    private javax.swing.JLabel venda_lbl2;
    private javax.swing.JLabel venda_lbl3;
    private javax.swing.JLabel venda_lbl4;
    private javax.swing.JLabel venda_lbl6;
    private javax.swing.JLabel venda_lbl7;
    private javax.swing.JButton venda_salvar;
    // End of variables declaration//GEN-END:variables

    public void reiniciaFormulario() {

        this.txt_id_cliVenda.setEnabled(false);
        this.txt_pedido.setEnabled(false);
        this.txt_nome_cliVenda.setEnabled(false);
        this.txt_codEquip.setEnabled(false);
        this.venda_lbl10.setEnabled(false);
        this.txt_equipInfo.setEnabled(false);
        this.btn_buscaEquip.setEnabled(false);
        this.txt_codEquip.setEnabled(false);
        this.jrb_cartao_credito.setEnabled(false);
        this.jrb_cartao_debito.setEnabled(false);
        this.jrb_avista.setEnabled(false);
        // **
        this.txt_busca.setEnabled(true);
        this.btn_buscaCli.setEnabled(true);

// ***************************************************
// deixa os valores vazios 
        this.txt_id_cliVenda.setText("");
        this.lbl_equipamento.setText("");
        this.txt_pedido.setText("");
        this.txt_nome_cliVenda.setText("");
        this.txt_codEquip.setText(" ");
        this.jrb_cartao_credito.setText(" ");
        this.jrb_cartao_credito.setText("Cartão de crédito");
        this.jrb_cartao_debito.setText(" ");
        this.jrb_cartao_debito.setText("Cartão de débito");
        this.jrb_avista.setText(" ");
        this.jrb_avista.setText("À vista");
        this.txt_valor.setText("");
        this.txt_busca.setText("");
        this.txt_equipInfo.setText("");
    } // limpa formulario
}
